﻿using Quartz.Logging;
using System;

namespace shop.Web.PlanTask
{

    /// <summary> Quartz 日志, 没有使用  </summary>
    public class QuartzLogFactory : ILogProvider
    {

        public Logger GetLogger(string name)
        {
            var _logger = NLog.LogManager.GetLogger("Quartz");

            return (level, func, exception, parameters) =>
            {
                if (level >= Quartz.Logging.LogLevel.Warn && func != null)
                {
                    //Console.WriteLine("[" + DateTime.Now.ToLongTimeString() + "] [" + level + "] " + func(), parameters);
                    if(level == Quartz.Logging.LogLevel.Error)
                    {
                        _logger.Error(func(), parameters);
                    }
                    else if(level == Quartz.Logging.LogLevel.Warn)
                    {
                        _logger.Warn(func(), parameters);
                    }
                    else if (level == Quartz.Logging.LogLevel.Fatal)
                    {
                        _logger.Fatal(func(), parameters);
                    }

                }
                return true;
            };
        }

        public IDisposable OpenNestedContext(string message)
        {
            throw new NotImplementedException();
        }

        public IDisposable OpenMappedContext(string key, object value, bool destructure = false)
        {
            throw new NotImplementedException();
        }
    }
}
